package iso3.pt.dao;

import iso3.pt.model.*;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		
		PtDAO hibernateDAO = PtDAO.getInstance();
		
		System.out.println("-------------Test de DAO-----------");
		
		//comprobacion getProfesor
		System.out.println("[TEST]getProfesor");
		System.out.println(hibernateDAO.getProfesor(1).getNombre()+"\n---------------");
		
		//comprobacion getAlumnos
		System.out.println("[TEST]getAlumnos");
		for (Iterator<Alumno> i = hibernateDAO.getAlumnos(1).iterator(); i.hasNext();)
		{
			Alumno alum = i.next();
			System.out.println(alum.getNombre());
		}
		System.out.println("---------------");
		
		//comprobacion getUnidades
		System.out.println("[TEST]getUnidades");
		for (Iterator<Unidad> i = hibernateDAO.getUnidades(1).iterator(); i.hasNext();)
		{
			Unidad  un= i.next();
			System.out.println(un.getTitulo());
		}
		System.out.println("---------------");
		
		//comprobacion getEvaluacionesAsignatura
		System.out.println("[TEST]getEvaluacionAsignatura");
		List<Evaluacion> listaEv = hibernateDAO.getEvaluacionesAsignatura(1);
		for(int i=0; i < listaEv.size(); i++)
		{
			System.out.println(listaEv.get(i).getAlumno().getDni()+": "+listaEv.get(i).getNota());
		}
		System.out.println("---------------");
		
		// comprobacion getEvaluaciones
			
		System.out.println("[TEST]getEvaluaciones");
		for (Iterator<Evaluacion> i = hibernateDAO.getEvaluaciones(1, 111111).iterator(); i.hasNext();)
		{
			Evaluacion eval = i.next();
			System.out.println(eval.getConcepto());
		}
		System.out.println("---------------");
		
		//comprobacion getAsignaturas
		System.out.println("[TEST]getAsignaturas");
		for (Iterator<Asignatura> i = hibernateDAO.getAsignaturas().iterator(); i.hasNext();)
		{
			Asignatura asig = i.next();
			System.out.println(asig.getNombre());
		}
		System.out.println("---------------");
		
		//comprobacion addEvaluacion
		System.out.println("[TEST]addEvaluacion");
		hibernateDAO.addEvaluacion("I haz the force!", 10, 3, 111111);
		System.out.println("[OK]Evaluacion added");
		System.out.println("---------------");
		
		//comprobacion getAlumno
		System.out.println("[TEST]getAlumno");
		Alumno alum = hibernateDAO.getAlumno(111111);
		
		System.out.println(alum.getDni());
		System.out.println(alum.getNombre());
		System.out.println(alum.getTelefono());
		
		System.out.println("---------------");
		
		//comprobacion  getAsignatura
		System.out.println("[TEST]getAsignatura");
		System.out.println(hibernateDAO.getAsignatura(1).getNombre());
		System.out.println("---------------");
		
		//comprobacion loginAlumno
		System.out.println("[TEST]loginAlumno");
		try
		{
			System.out.println(hibernateDAO.loginAlumno(111111,"pass1").getNombre());
		}catch(UserNotFoundException une )
		{
			System.out.println(une.getMessage());
		}catch(IncorrectPasswordException ipe)
		{
			System.out.println(ipe.getMessage());
		}
		System.out.println("---------------");
		
		//comprobacion getAsignaturas
		System.out.println("[TEST]getAsignaturas");
		System.out.println(hibernateDAO.getAsignaturas(111111).size());
		System.out.println("---------------");
		
		//comprobacion matricular
		System.out.println("[TEST]matricular");
		hibernateDAO.matricular(111111, 2);
		System.out.println(hibernateDAO.getAsignaturas(111111).size());
		System.out.println("---------------");
		
		//comprobacion desmatricular
		System.out.println("[TEST]desmatricular");
		hibernateDAO.desmatricular(111111, 2);
		System.out.println(hibernateDAO.getAsignaturas(111111).size());
		System.out.println("---------------");
		
		//comprobacion getProfesorByDni y loginProfesor
		System.out.println("[TEST]getProfesorByDni & loginProfesor");
		try
		{
			System.out.println(hibernateDAO.loginProfesor(123456789,"pass1").getNombre());
		}catch(UserNotFoundException une )
		{
			System.out.println(une.getMessage());
		}catch(IncorrectPasswordException ipe)
		{
			System.out.println(ipe.getMessage());
		}
		System.out.println("---------------");
		
		//comprobacion  getAsignaturasProfesor
		System.out.println("[TEST]getAsignaturasProfesor");
		for (Iterator<Asignatura> i = hibernateDAO.getAsignaturasProfesor(1).iterator(); i.hasNext();)
		{
			Asignatura asig = i.next();
			System.out.println(asig.getNombre());
		}
		System.out.println("---------------");
		
	}


}
